#ifndef LHC_WIN32_EXCEPTION_H_INCLUDED_
#define LHC_WIN32_EXCEPTION_H_INCLUDED_

#ifdef _WIN32

#include "Exception.h"
#include <Windows.h>

namespace lhcutils
{

class Win32Exception : public lhcutils::Exception
{
private:
	DWORD m_errorCode;

public:
	Win32Exception(StringPtr nonSystemMessage, const char* codeFile, int codeLine, DWORD errorCode);
	DWORD GetErrorCode() const;
	//StringPtr GetNonSystemMessage() const;
	//StringPtr GetSystemMessage() const;
	virtual lhcutils::StringPtr UnicodeWhat() const;
};

// Make sure that GetLastError is called before an expression evaluating to StringPtr nonSystemMessage
// is evaluated, possibly trashing the last eror code.
#define THROW_WIN32(nonSystemMessage) { DWORD lastError_ = GetLastError(); throw lhcutils::Win32Exception((nonSystemMessage), __FILE__, __LINE__, lastError_); }

}

#endif

#endif

/*
 Copyright 2011 Greg Najda

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
